package com.neusoft.elmboot.service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.neusoft.elmboot.config.TokenConfig;
import com.neusoft.elmboot.mapper.UserMapper;
import com.neusoft.elmboot.po.User;
import com.neusoft.elmboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserSeriveImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public JSONObject getUserByIdByPass(User user) {
        User ret = userMapper.getUserByIdByPass(user);
        if (ret == null) {
            return null;
        }
        ret.setPassword(null);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("token", TokenConfig.createToken(ret));
        jsonObject.put("user", ret);
        return jsonObject;
    }

    @Override
    public User getUserById(String userId) {
        return userMapper.getUserById(userId);
    }

    @Override
    public int saveUser(User user) {
        return userMapper.saveUser(user);
    }

    @Override
    public int updateUserById(User user) {
        return userMapper.updateUserById(user);
    }

    @Override
    public int removeUser(User user) {
        userMapper.removeCart(user);
        userMapper.removeOrders(user);
        userMapper.removeComments(user);
        userMapper.removeDeliveryaddress(user);
        userMapper.removeIntegraltrans(user);
        userMapper.removeIntegrationlog(user);
        userMapper.removeWallet(user);
        return userMapper.removeUser(user);
    }
}
